package cn.micro.system.manage.service.impl;

import cn.micro.system.manage.entity.SysOdsOperLog;
import cn.micro.system.manage.entity.vo.SysOperLogQueryVo;
import cn.micro.system.manage.mapper.SysOdsOperLogMapper;
import cn.micro.system.manage.service.SysOdsOperLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 操作日志记录 服务实现类
 * </p>
 *
 * @author wr
 * @since 2023-12-25
 */
@Service
public class SysOdsOperLogServiceImpl extends ServiceImpl<SysOdsOperLogMapper, SysOdsOperLog> implements SysOdsOperLogService {

    @Override
    public void saveSysLog(SysOdsOperLog sysOperLog) {
        this.baseMapper.insert(sysOperLog);
    }

    @Override
    public List<SysOdsOperLog> selectPage(int page, int size, SysOperLogQueryVo sysOperLogQueryVo) {
        PageHelper.startPage(page, size);
        LambdaQueryWrapper<SysOdsOperLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(sysOperLogQueryVo.getTitle()), SysOdsOperLog::getTitle, sysOperLogQueryVo.getTitle())
                .eq(StringUtils.isNotBlank(sysOperLogQueryVo.getOperName()), SysOdsOperLog::getOperName, sysOperLogQueryVo.getOperName())
                .ge(StringUtils.isNotBlank(sysOperLogQueryVo.getCreateTimeBegin()), SysOdsOperLog::getCreateTime, sysOperLogQueryVo.getCreateTimeBegin())
                .le(StringUtils.isNotBlank(sysOperLogQueryVo.getCreateTimeEnd()), SysOdsOperLog::getCreateTime, sysOperLogQueryVo.getCreateTimeEnd())
                .orderByDesc(SysOdsOperLog::getCreateTime);
        return this.baseMapper.selectList(queryWrapper);
    }
}
